package com.shd.edanpei.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseQuickImageAdapter;
import com.shd.edanpei.presenter.contract.ListviewItemOnClick;

import java.util.List;

/**
 * Created by mc on 2019/2/18.
 * wushuaijun
 */

public class HomeBannerAdapter1 extends RecyclerView.Adapter<HomeBannerAdapter1.ViewHolder> {

    private List<String> list;
    private Context context;
    private ListviewItemOnClick listviewItemOnClick;

    public HomeBannerAdapter1(Context context,List<String> list,ListviewItemOnClick listviewItemOnClick){
        this.list=list;
        this.context=context;
        this.listviewItemOnClick=listviewItemOnClick;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_banner,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {

//        if (holder.getLayoutPosition() != getData().size() - 1) {
//            holder.getView(R.id.right).setVisibility(View.GONE);
//        } else {
//            holder.getView(R.id.right).setVisibility(View.VISIBLE);
//        }

        Log.e("adpater","position"+position%list.size());
//        holder.left.setVisibility(position==20?View.VISIBLE:View.GONE);
        Glide.with(context).load(list.get(position%list.size())).into(holder.iv_banner);
        holder.iv_banner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listviewItemOnClick.onItemClick(null,position);
            }
        });

    }

    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }
//
//    public HomeBannerAdapter1(Context context) {
//        super(context, R.layout.item_home_banner);
//    }
//
//    @Override
//    protected void convert(BaseViewHolder helper, String item) {
//
//
//        if (helper.getLayoutPosition() != getData().size() - 1) {
//            helper.getView(R.id.right).setVisibility(View.GONE);
//        } else {
//            helper.getView(R.id.right).setVisibility(View.VISIBLE);
//        }
//
//
//        Glide.with(mContext).load(item).into((ImageView) helper.getView(R.id.iv_banner));
//    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_banner;
        public View left;

        public ViewHolder(View itemView) {
            super(itemView);
            iv_banner= (ImageView) itemView.findViewById(R.id.iv_banner);
            left=itemView.findViewById(R.id.left);
        }
    }



}
